{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import torch.nn as nn"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "class DenseBlock(nn.Module):\n",
    "    def __init__(self, input_num_planes, rate_inc):\n",
    "        super(DenseBlock, self).__init__()\n",
    "        self.batch_norm1 = nn.BatchNorm2d(input_num_planes)\n",
    "        self.conv_layer1 = nn.Conv2d(in_channels=input_num_planes, out_channels=4*rate_inc, kernel_size=1, bias=False)\n",
    "        self.batch_norm2 = nn.BatchNorm2d(4*rate_inc)\n",
    "        self.conv_layer2 = nn.Conv2d(in_channels=4*rate_inc, out_channels=rate_inc, kernel_size=3, padding=1, bias=False)\n",
    "    def forward(self, inp):\n",
    "        op = self.conv_layer1(F.relu(self.batch_norm1(inp)))\n",
    "        op = self.conv_layer2(F.relu(self.batch_norm2(op)))\n",
    "        op = torch.cat([op,inp], 1)\n",
    "        return op\n",
    "\n",
    "class TransBlock(nn.Module):\n",
    "    def __init__(self, input_num_planes, output_num_planes):\n",
    "        super(TransBlock, self).__init__()\n",
    "        self.batch_norm = nn.BatchNorm2d(input_num_planes)\n",
    "        self.conv_layer = nn.Conv2d(in_channels=input_num_planes, out_channels=output_num_planes, kernel_size=1, bias=False)\n",
    "    def forward(self, inp):\n",
    "        op = self.conv_layer(F.relu(self.batch_norm(inp)))\n",
    "        op = F.avg_pool2d(op, 2)\n",
    "        return op"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
